<?php
namespace Admin\Model;
use Think\Model\RelationModel;
class MajorModel extends RelationModel{
    
    protected $_link = array(
        'schoolArea' => array(
            'mapping_type'      => self::HAS_ONE,
            'mapping_key'       => 'class',
            'mapping_fields'    => 'dataname',
            'foreign_key'       => 'datavalue',
            'class_name'        => 'Cascadedata',
            'condition'         => 'datagroup = "major"',
            'as_fields'         => 'dataname:classname'
        ),
    
    );
    
    /**
     * 查询点击层次数据
     * $class datavalue级联数据值
     * $level 层次
     */
    function getMajorLevel($class,$level){
        $casClass = D('cascadedata');
        switch($level){  //判断点击第几层
            case 0:
                $majorTwo = $casClass->where("datavalue>".$class." and level = 1 and datagroup='major'")->min('datavalue'); //获得第二层数据最小值
                $majorNum = $casClass->where("datavalue>".$majorTwo." and datavalue<".($majorTwo+1)." and level = 2 and datagroup='major'")->min('datavalue');
                break;
            case 1:
                $majorNum = $casClass->where("datavalue>".$class." and datavalue<".($class+1)." and level = 2 and datagroup='major'")->min('datavalue');
                break;
            case 2:
                $majorNum = $class;
                break;
        }
        return $majorNum;
    }

}